﻿Imports System.Xml

Namespace Stories
	Public Class ParagraphStyleRange
		Inherits Child

		Public Sub New()
			Me.Children = New List(Of Child)
		End Sub

		Property Children As List(Of Child)

		Property AppliedParagraphStyle As String

		Shared Function ReadXml(reader As XmlReader) As ParagraphStyleRange
			Dim psr As New ParagraphStyleRange()

			psr.AppliedParagraphStyle = reader.GetAttribute("AppliedParagraphStyle")
			While reader.Read()
				Select Case reader.Name
					Case "Footnote"
						psr.Children.Add(Footnote.ReadXml(reader))
					Case "GaijiOwnedItemObject"
						psr.Children.Add(GaijiOwnedItemObject.ReadXml(reader))
					Case "Note"
						psr.Children.Add(Note.ReadNote(reader))
					Case "Table"
						psr.Children.Add(Table.ReadXml(reader))
					Case "TextVariableInstance"
						psr.Children.Add(TextVariableInstance.ReadXml(reader))

					Case "HiddenText"
						psr.Children.Add(HiddenText.ReadXml(reader))
					Case "XMLElement"
						psr.Children.Add(XmlElement.ReadXml(reader))


					Case "CharacterStyleRange"
						psr.Children.Add(CharacterStyleRange.ReadXml(reader))

					Case "Content"
						psr.Children.Add(New Content(reader.ReadString()))
					Case "Br"
						psr.Children.Add(New Br())
					Case "ParagraphStyleRange"
						If reader.NodeType = XmlNodeType.EndElement Then Exit While
					Case Else
						Debug.WriteLine("Unrecognized element: {0} in element: {1}", reader.Name, "ParagraphStyleRange")
				End Select
			End While

			Return psr
		End Function

	End Class
End Namespace